package binance.tag

class ObserveTagLib {
    def observe = { attrs ->
        def controller = attrs.controller
        def action = attrs.action
        def subject = attrs.subject
        def update = attrs.update
        def reference = attrs.reference

        out << "<script language='javascript'>"
        out << "new PeriodicalExecuter(function() {"
        out << "if (\$(\'$reference\') == null && \$(\'${subject}\').value != '' || \$(\'$reference\') != null && \$(\'${subject}\').value != \$(\'$reference\').value) {\n"
        out << remoteFunction(controller:controller,
            action:action,
            update:update,
            params:"'$subject='+\$('$subject').value"
            )
        out << "}\n"
        out << "}, 0.5);"
        out << "</script>"
    }
}
